package md.w;

import java.util.Scanner;

public class Demo0001 {
	static boolean a1;
	static boolean a2;
	static boolean a3;
	static boolean a4;
	static boolean a6;
	static boolean a5;
	static boolean a7;
	static String a[][] = new String[100][4];
	static String book[][] = new String[100][5];
	static String cbs [][] = new String[100][6];
	static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args) {
		csh();
		login();
		System.out.println("请输入数字进行选择：1 图书管理  2 出版社管理  3 退出登录  4 退出系统");
		int key2 = scanner.nextInt();
		switch (key2) {
		case 1:
			book1();
			break;
		case 2:
			book2();
			break;
		case 3:
			book3();
			break;
		case 4:
			book4();
			break;
		default:
			break;
		}
	}
	private static void book4() {
		System.exit(0);
	}
	private static void book3() {
		System.out.println("已退出登录！");
		login();
	}
	private static void book2() {
		System.out.println("请输入：1.增加 2.删除 3.更新 4.根据出版社名称查询 5.查询所有出版社 6.返回上一级菜单");
		book21();
	}
	private static void book21() {
		int key3=scanner.nextInt();
		switch (key3) {
		case 1:
			int index = -1;
			for (int i = 0; i < cbs.length; i++) {
				if (cbs[i][0] == null) {
					index = i;
				}
			}
			System.out.println("请输入出版社名称：");
			String cbsname=scanner.next();
			System.out.println("请输入出版社地址：");
			String cbsdz=scanner.next();
			System.out.println("请输入出版社联系人：");
			String cbslxr=scanner.next();
			cbs[index][0]=cbsname;
			cbs[index][1]=cbsdz;
			cbs[index][2]=cbslxr;
			book2();
			break;
		case 2:
			System.out.println("请输入出版社名称:");
			String cbsname2 = scanner.next();
			int bb=-1;
			for (int i = 0; i < book.length; i++) {
				if (cbsname2.equals(cbs[i][1])) {
					a1=true;
					bb=i;
					break;
				}
			}
			if (a1) {
				cbs[bb][0] = null;
				cbs[bb][1] = null;
				cbs[bb][2] = null;
			} else {
				System.out.println("未找到出版社名称");
			}
			book2();
			break;
		case 3:
			System.out.println("请输入要更新的出版社名称：");
			String a1a=scanner.next();
			int ara=-1;
			for (int i = 0; i < cbs.length; i++) {
				if (a1a.equals(cbs[i][0])) {
					a2 = true;
					ara=i;
					break;
				}
			}
			if (a2) {
				System.out.println("请输入要更新的地址：");
				String a1aa=scanner.next();
				System.out.println("请输入要更新的联系人姓名：");
				String a2a=scanner.next();
				cbs[ara][1]=a1aa;
				cbs[ara][2]=a2a;
			} else {
				System.out.println("未找到出版社");
			}
			book2();
			break;
		case 4:
			System.out.println("请输入出版社名称：");
			String a5=scanner.next();
			int a6=-1;
			for (int i = 0; i < cbs.length; i++) {
				if (a5.equals(cbs[i][0])) {
					a3 = true;
					a6=i;
					break;
				}
			}
			if (a3) {
				System.out.println("出版社名称："+cbs[a6][0]);
				System.out.println("出版社地址："+cbs[a6][1]);
				System.out.println("出版社联系人："+cbs[a6][2]);
			} else {
				System.out.println("未找到出版社");
			}
			book2();
			break;
		case 5:
			for (int i = 0; i < a.length; i++) {
				System.out.println(cbs[i][0]);
			}
			book2();
			break;
		case 6:
			back();
			break;

		default:
			break;
		}
	}
	private static void book1() {
		System.out.println("1.增加 2.删除 3.更新 4.查询 5.返回上一级菜单");
		book11();
	}
	private static void book11() {
		int key3 = scanner.nextInt();
		switch (key3) {
		case 1:
			System.out.println("请输入图书ISBN:");
			String ISBN = scanner.next();
			System.out.println("请输入书名:");
			String bookname = scanner.next();
			System.out.println("请输入价格:");
			String money = scanner.next();
			System.out.println("请输入出版社:");
			String chubanshe = scanner.next();
			System.out.println("请输入作者:");
			String zuozhename = scanner.next();
			for (int i = 0; i < book.length; i++) {
				if (ISBN.equals(book[i][0])) {
					a6 = true;
					break;
				}
			}
			if (a6) {
				System.out.println("ISBN不能重复");

			} else {
				int index = -1;
				for (int i = 0; i < book.length; i++) {
					if (book[i][0] == null) {
						index = i;
					}
				}
				book[index][0] = ISBN;
				book[index][1] = bookname;
				book[index][2] = money;
				book[index][3] = chubanshe;
				book[index][4] = zuozhename;
			}
			book1();
			break;
		case 2:
			System.out.println("请输入书名:");
			String bookname1 = scanner.next();
			int cc=-1;
			for (int i = 0; i < book.length; i++) {
				if (bookname1.equals(book[i][1])) {
					a7=true;
					cc=i;
					break;
				}
			}
			if (a7) {
				book[cc][0] = null;
				book[cc][1] = null;
				book[cc][2] = null;
				book[cc][3] = null;
				book[cc][4] = null;
			} else {
				System.out.println("未找到书名");
			}
			book1();
			break;
		case 3:
			System.out.println("请输入ISBN号：");
			String ISBN1 = scanner.next();
			int index = -1;
			for (int i = 0; i < book.length; i++) {
				if (ISBN1.equals(book[i][0])) {
					a5 = true;
					index = i;
					break;
				}
			}
			if (a5) {
				System.out.println("请输入新的书名：");
				String bookname2 = scanner.next();
				System.out.println("请输入新的价格：");
				String money1 = scanner.next();
				System.out.println("请输入新的出版社：");
				String chubanshe1 = scanner.next();
				System.out.println("请输入新的作者：");
				String zuozhe1 = scanner.next();
				book[index][1] = bookname2;
				book[index][2] = money1;
				book[index][3] = chubanshe1;
				book[index][4] = zuozhe1;
			} else {
				System.out.println("该ISBN号不存在！！！");
			}
			update();
			break;
		case 4:
			System.out.println("请输入查询种类：1.isbn 2.书名（模糊） 3.出版社 4. 作者 5. 价格范围 6.查询所有 7.返回上一级");
			check();
			break;
		case 5:
			back();
			break;
		default:
			break;
		}
	}
	private static void check() {
		int key4=scanner.nextInt();
		switch (key4) {
		case 1:
			System.out.println("请输入ISBN号：");
			String c1=scanner.next();
			int c2=-1;
			for (int i = 0; i < book.length; i++) {
				if (c1.equals(book[i][0])) {
					c2=i;
				}
			}
			System.out.println(book[c2][0]);
			System.out.println(book[c2][1]);
			System.out.println(book[c2][2]);
			System.out.println(book[c2][3]);
			System.out.println(book[c2][4]);
			break;
		case 2:
			//模糊查询
			break;
		case 3:
			System.out.println("请输入出版社：");
			String c3=scanner.next();
			int c4=-1;
			for (int i = 0; i < cbs.length; i++) {
				if (c3.equals(cbs[i][0])) {
					c4=i;
				}
			}
			System.out.println(cbs[c4][0]);
			System.out.println(cbs[c4][1]);
			System.out.println(cbs[c4][2]);
			break;
		case 4:
			System.out.println("请输入作者名称：");
			String c5=scanner.next();
			int c6=-1;
			for (int i = 0; i < book.length; i++) {
				if (c5.equals(book[i][4])) {
					c6=i;
				}
			}
			System.out.println(book[c6][0]);
			System.out.println(book[c6][1]);
			System.out.println(book[c6][2]);
			System.out.println(book[c6][3]);
			System.out.println(book[c6][4]);
			break;
		case 5:
			System.out.println("请输入价格：");
			String c7=scanner.next();
			int c8=-1;
			for (int i = 0; i < book.length; i++) {
				if (c7.equals(book[i][2])) {
					c8=i;
				}
			}
			System.out.println(book[c8][0]);
			System.out.println(book[c8][1]);
			System.out.println(book[c8][2]);
			System.out.println(book[c8][3]);
			System.out.println(book[c8][4]);
			break;
		case 6:
			System.out.println("ISBN    书名         价格    出版社           作者");
			for (int i = 0; i < a.length; i++) {
				for (int j = 0; j < a.length; j++) {
					System.out.print(book[i][j]+"  ");
				}
				System.out.println();
			}
			break;
		case 7:
			book1();
			break;
		default:
			break;
		}
	}
	private static void back() {
		System.out.println("请输入数字进行选择：1 图书管理  2 出版社管理  3 退出登录  4 退出系统");
		int key2 = scanner.nextInt();
		switch (key2) {
		case 1:
			book1();
			break;
		case 2:
			book2();
			break;
		case 3:
			book3();
			break;
		case 4:
			book4();
			break;
		default:
			break;
		}
	}
	private static void update() {
		System.out.println("请输入ISBN号：");
		String ISBN1 = scanner.next();
		int index = -1;
		for (int i = 0; i < book.length; i++) {
			if (ISBN1.equals(book[i][0])) {
				a5 = true;
				index = i;
				break;
			}
		}
		if (a5) {
			System.out.println("请输入新的书名：");
			String bookname2 = scanner.next();
			System.out.println("请输入新的价格：");
			String money = scanner.next();
			System.out.println("请输入新的出版社：");
			String cbs = scanner.next();
			System.out.println("请输入新的作者：");
			String zz = scanner.next();
			book[index][1] = bookname2;
			book[index][2] = money;
			book[index][3] = cbs;
			book[index][4] = zz;
		} else {
			System.out.println("该ISBN号不存在！！！");
		}
		update();
	}
	public static void login() {
		System.out.println("欢迎来到闽大图书管理系统！");
		System.out.println("1.登录 2.注册");
		int key = scanner.nextInt();
		switch (key) {
		case 1:
			while (true) {
				System.out.println("请输入用户名：");
				String b = scanner.next();
				System.out.println("请输入密码：");
				String c = scanner.next();
				for (int i = 0; i < a.length; i++) {
					if (b.equals(a[i][1]) && c.equals(a[i][2])) {
						a4 = true;
						break;
					}
				}
				if (a4) {
					System.out.println("登录成功！");
					System.out.println(b + ",欢迎您使用闽大书籍管理系统！！！");
					break;
				} else {
					System.out.println("输入错误，请重新输入！");
				}
			}
			break;
		case 2:
			int index = -1;
			for (int i = 0; i < a.length; i++) {
				if (a[i][0] == null) {
					index = i;
				}
			}
			System.out.println("请输入所属部门：");
			String d = scanner.next();
			System.out.println("请输入用户名：");
			String e = scanner.next();
			System.out.println("请输入密码：");
			String f = scanner.next();
			System.out.println("请输入用户角色：");
			String g = scanner.next();
			System.out.println("注册成功");
			a[index][0] = d;
			a[index][1] = e;
			a[index][2] = f;
			a[index][3] = g;
			login();
			break;
		default:
			break;
		}
	}
	private static void csh() {
		a[0] [0]="软件部";
		a [0] [1]="admin";
		a [0] [2]="123";
		a [0] [3]="软件开发员";
		
		a [1] [0]="行政部";
		a [1] [1]="李四";
		a [1] [2]="1234";
		a [1] [3]="管理员";
		
		book[0][0]="0001";
		book[0][1]="理想国";
		book[0][2]="50";
		book[0][3]="清华大学出版社";
		book[0][4]="柏拉图";
		
		book[1][0]="0002";
		book[1][1]="狂人日记";
		book[1][2]="50";
		book[1][3]="北京大学出版社";
		book[1][4]="鲁迅";
		
		book[2][0]="0003";
		book[2][1]="刑罚的历史";
		book[2][2]="50";
		book[2][3]="中国政法大学出版社";
		book[2][4]="罗翔";
		
		cbs[0][0]="北京大学出版社";
		cbs[0][1]="北京";
		cbs[0][2]="123456789";
		
		cbs[0][0]="清华大学出版社";
		cbs[0][1]="北京";
		cbs[0][2]="1234567891";
		
		cbs[0][0]="中国政法大学出版社";
		cbs[0][1]="北京";
		cbs[0][2]="12345678912";
	}
	
}